<?php

class IndexAction extends CommonAction {
	//后台首页
    public function index(){
    	$userid = session('userid');
    	
    	if(isset($userid)){
    		$langModel = M('Lang');
    		$langList = $langModel->where(array('admin_ok'=>'2'))->select();
    		$showLang = array();
    		
    		foreach($langList as $key=>$value){
    			if($value['name']==session('lang')){
    				$showLang['name'] = $value['name'];
    				$showLang['info'] = $value['info'];
    			}
    		}
    		
    		$this->showLang = $showLang;
    		$this->langList = $langList;
    		
    		$this->morenurl = "__APP__/system/index";
        	$this->display();
    	}else{
			$this->error('验证失效，重新登陆！', '__APP__/login/index');
    	}
    }
    
    public function editLang(){
    	$lang = $this->_post("lang");
    	$userid = session('userid');
		$userModel = M('User');
		
		$data['lang'] = $lang;
		
		$result = $userModel->where("admin_id='{$userid}'")->save($data);
        if(false !== $result) {
        	session('lang',$lang);
        	$this->json(array('statusCode'=>200,'message'=>'修改成功！'));
        }else{
        	$this->json(array('statusCode'=>300,'message'=>'修改错误！'));
        }
    }
}